package org.jc.oss.config;

import jakarta.annotation.Resource;
import org.jc.oss.service.StorageService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

/**
 * 功能描述
 *
 * @author wanghongqian
 * @date 2024/07/04 16:03
 */
@Configuration
@RefreshScope
public class StorageConfig {

    @Value("${storage.service.type}")
    private String storageType;

    @Resource
    @Lazy
    private StorageService minioStorageServiceImpl;

    @Resource
    @Lazy
    private StorageService aliyunStorageServiceImpl;

    @Bean
    @RefreshScope
    public StorageService storageService(){
        switch (storageType){
            case "minio":
                return minioStorageServiceImpl;
            case "aliyun":
                return aliyunStorageServiceImpl;
            default:
                throw new RuntimeException("未找到对应的文件存储处理器");
        }
    }
}
